package com.example.bishe.controller.Test;

import com.alibaba.fastjson.JSONObject;
import com.example.bishe.toolclass.ApiReturnDate;
import com.example.bishe.toolclass.GitTonk;
import com.example.bishe.toolclass.JsonValue;
import com.example.bishe.toolclass.MyEnum;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author yws
 * @Date 2022/4/6 23:27
 */
@RestController
@RequestMapping("/information")
public class Information {
    @Resource
    GitTonk gitTonk;
    @Resource
    ApiReturnDate apiReturnDate;
    @Resource
    JsonValue jsonValue;

    @RequestMapping("/departmentAll")
    public void departmentAll() {//获取所有的部门信息
        String access_token = gitTonk.AccessToken("useraccess_token");
        //拼接访问的URL
        String user = MyEnum.DEPARTMENT_CAOZUO.getValue() + "list?" +
                "access_token=" + access_token;
        JSONObject mydate = apiReturnDate.Mydate(user);
        System.out.println(mydate);
        HashMap<String, String> value = jsonValue.getValue(mydate, "errcode", "errmsg", "department");
        Set set = new HashSet();
        set = value.entrySet();
        set.forEach(System.out::println);
    }

    @RequestMapping("/userAll")
    public void userAll(){//获取所有的成员的信息
        String access_token = gitTonk.AccessToken("useraccess_token");
        //拼接访问的URL
        String user = MyEnum.USER_CAOZUO.getValue() + "simplelist?" +
                "access_token=" + access_token+"&department_id="+1+"&fetch_child="+1;
        JSONObject mydate = apiReturnDate.Mydate(user);
        System.out.println(mydate);
        HashMap<String, String> value = jsonValue.getValue(mydate, "errcode", "errmsg", "userlist");
        Set set = new HashSet();
        set = value.entrySet();
        set.forEach(System.out::println);
    }
}
